import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    count: 0,
    time: '',
    totab: [
      { id: 1, text: '111111', done: true },
      { id: 2, text: '222222', done: false }
    ]
  },
  mutations: {
    add (state, num) {
      state.count += num
    },
    timeFun (state) {
      state.time = new Date()
    }
  },
  actions: {
    add1 ({commit}) {
      commit('add', 2)
    },
    addCeShi ({commit}) {
      setTimeout(() => {
        commit('add', 3)
      }, 1000)
    },
    timeAct ({commit}) {
      setInterval(() => {
        commit('timeFun')
      }, 1000)
    }
  },
  getters: {
    tabFil (state) {
      return state.totab.filter(item => item.done)
    },
    tabFil2 (state, getters) {
      return state.totab.length + getters.tabFil.length
    }
  },
  modules: {

  }
})

export default store
